<?php get_template_part('templates/page', 'header'); ?>
<ul class="stream">
    <?php
    $paged = 1;
    if (get_query_var('paged')) {
        $paged = get_query_var('paged');
    } elseif (get_query_var('page')) {
        $paged = get_query_var('page');
    }
    $author = get_queried_object();
    $url = get_author_posts_url($author->ID);
    $args = array('post_type' => 'joke', 'paged' => $paged, 'post_status' => 'publish', 'author' => $author->ID);
    $joke_query = new WP_Query($args);

    while ($joke_query->have_posts()) : $joke_query->the_post();
        $author_url = esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>
        <li data-id="<?php the_id(); ?>">
            <a href="<?php echo $author_url; ?>"><img src="<?php the_author_meta('avatar'); ?>" class="user"></a>

            <div class="post">
                <h3>
                    <a href="<?php echo $author_url; ?>"><?php the_author_meta('nickname'); ?></a>
                    <time datetime="<?php the_time('c'); ?>"><?php the_time('d-m H:i'); ?></time>
                </h3>
                <?php the_content(); ?>
                <div class="interaction">
                    <a href="<?php echo esc_url(get_permalink()); ?>" class="comment">
                        <span class="glyphicon glyphicon-comment"></span> <?php _e('Comment', 'roots'); ?>(<span
                            class="comment-count"><?php echo get_comments_number(); ?></span>)
                    </a>
                </div>
            </div>
        </li>
    <?php endwhile; ?>
</ul>
<?php if ($joke_query->max_num_pages > 1) { ?>
    <div class="row">
        <div class="col-md-12 text-center">
            <ul class="pagination">
                <?php if ($paged > 1) { ?>
                    <li><a rel="prev"
                           href="<?php echo $url; ?>?page=<?php echo($paged - 1); ?>"><?php _e('Prev Page', 'roots'); ?></a>
                    </li>
                <?php } ?>
                <li class="active"><a href="#"><?php echo $paged; ?></a></li>
                <?php if ($paged < $joke_query->max_num_pages) { ?>
                    <li><a rel="next"
                           href="<?php echo $url; ?>?page=<?php echo($paged + 1); ?>"><?php _e('Next Page', 'roots'); ?></a>
                    </li>
                <?php } ?>
            </ul>
        </div>
    </div>
<?php } ?>
